#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef unsigned float_bits;
typedef unsigned char* bit_transform;
unsigned swift_f2un(bit_transform b);
float_bits float_f2i(float_bits f);
int main()
{
    unsigned* un_p;
    float f;
    FILE *file;
    file=fopen("test_0xFFFF0000-0xFFFFFFFE.txt","w");
    unsigned i=1;
    un_p=&f;
    fprintf(file,"%20s%20s%20s\n","original","tested","verified" );
    for (i = 0xFFFF0000; i<=0xFFFFFFFE; i++) {
      *un_p=i;
      fprintf(file,"%20.6f", f);
      if(float_f2i(swift_f2un((bit_transform)un_p))==0x80000000)
          fprintf(file,"%20s","0x80000000");
      else
          fprintf(file,"%20d",(int)float_f2i(swift_f2un((bit_transform)un_p)));
      if(float_f2i(swift_f2un((bit_transform)un_p))==0x80000000)
          fprintf(file,"%20s\n","0x80000000");
      else
          fprintf(file,"%20d\n",(int)f);
    }
fclose(file);
    printf("\nHello world!\n");
    return 0;
}

float_bits float_f2i(float_bits f)
{
    unsigned sign=f>>31;
    unsigned exp=f>>23&0xFF;
    int exp_E=(int)exp-127;
    unsigned frac=f&0x7FFFFF;
    frac=frac|0x800000;
    if(exp==0)return f&0x80000000;
    if(exp_E>30)return 0x80000000;
    if(exp_E<0)return 0;
    return (unsigned)(frac*pow(2,exp_E-23))|sign<<31;
}

unsigned swift_f2un(bit_transform b)
{
    unsigned un=0;
    unsigned sign[4];
    sign[0]=(unsigned)b[0];
    sign[1]=((unsigned)b[1])<<8;
    sign[2]=((unsigned)b[2])<<16;
    sign[3]=((unsigned)b[3])<<24;
    un=sign[0]|sign[1]|sign[2]|sign[3];
    return un;
}
